package assignment1;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@SuppressWarnings("serial")
public class MyFrame extends JFrame
{   /*This class will be used to add components to a JFrame and will also create
    an instance of the MyControlPanel class to add the user controls. It will be
    called in the main method for the assingment to show the project.*/
    
    static DrawShape pane; //creates a DrawShape panel to show shapes.
    JPanel primaryPane; //creates a panel which will eventually hold two panels
    static MyShape myShape = new MyShape(); //creates a myShape 

    //assign action listeners to the three JMenuItems.
    Listener1 sListener = new Listener1();
    Listener2 cListener = new Listener2();
    Listener3 tListener = new Listener3();

    //create the three action listeners.
    class Listener1 implements ActionListener
    {   //override the actionPerformed method to listen for a user action.
        @Override
        public void actionPerformed (ActionEvent ae)
        {   MyFrame.myShape = new Square(); //make the myShape a square
            DrawShape.shapeNum = 1; //make the shapeNum equal one
            DrawShape square = new DrawShape(); //create a new DrawShape panel.
            pane.add(square); //add the DrawShape panel to the current pane.
            repaint(); //repaint the pane to show the shape.
        }
    }

    class Listener2 implements ActionListener
    {   @Override
        public void actionPerformed (ActionEvent ae)
        {   MyFrame.myShape = new Circle(); //make the myShape a circle
            DrawShape.shapeNum = 2;//make the shapeNum equal two
            DrawShape circle = new DrawShape(); //create a new DrawShape panel.
            pane.add(circle); //add the DrawShape panel to the current pane.
            repaint(); //repaint the pane to show the shape.
        }
    }

    class Listener3 implements ActionListener
    {   @Override
        public void actionPerformed (ActionEvent ae)
        {   MyFrame.myShape = new Triangle(); //make the myShape a triangle
            DrawShape.shapeNum = 3; //make the shapeNum equal three
            DrawShape triangle = new DrawShape();//create a new DrawShape panel.
            pane.add(triangle); //add the DrawShape panel to the current pane.
            repaint(); //repaint the pane to show the shape.
        }
    }

{   
    pane = new DrawShape(); // create the DrawShape panel.
    pane.setPreferredSize(new Dimension(500,300)); // set the size of the panel.
    
    //create an instance of MyControlPanel to show the JSlider and JTextFields
    MyControlPanel myPane = new MyControlPanel(); 
    myPane.startControl(); //use the method to start the control panel.
    myPane.setPreferredSize(new Dimension(500,100)); //set the size of the panel

    JMenuBar menubar; //create a menu bar.
    JMenu menu; //create a menu.
    JMenuItem item1, item2, item3; //create menu items.

    // Create the framed window to show on screen
    this.setTitle("Mark Mckillion - B00540772"); //shows my details in the frame
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //set to close
    this.setLayout(new BorderLayout());//set a new border layout for the frame.

    menubar = new JMenuBar(); //create the menu bar.
    this.setJMenuBar(menubar); //set the menu.

    menu = new JMenu(); // create a menu
    menu.setText("Shapes"); // give the menu a title.
    menubar.add(menu); // add the menu to the menu bar.

    //create the menu items that the user will click to choose a shape.
    item1 = new JMenuItem("Square");
    item2 = new JMenuItem("Circle");
    item3 = new JMenuItem("Triangle");
    
    //add the menu items to the menu.
    menu.add(item1);
    menu.add(item2);
    menu.add(item3);
    
    //add the action listeners to the menu items.
    item1.addActionListener(sListener); 
    item2.addActionListener(cListener);
    item3.addActionListener(tListener);

    // Show the JFrame on the screen
    this.setSize(550, 500);
    this.setVisible(true);
    
    //add the two panels to a main panel and add the overall panel to the frame.
    primaryPane = new JPanel();
    primaryPane.add(pane);
    primaryPane.add(myPane);
    add(primaryPane);
    }
}
